package cn.bobdeng.spc.mainserver.security;

import cn.bobdeng.userrole.UserRepos;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String loginName) throws UsernameNotFoundException {
        return UserRepos.userRepository.findByLoginName(loginName)
                .map(MyUserDetails::new)
                .orElseThrow(() -> new UsernameNotFoundException("登录名或密码错误"));
    }

}
